package com.webwork.mood.system.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.webwork.mood.system.dao.JobDao;
import com.webwork.mood.system.dataobject.Job;
import com.webwork.mood.system.service.JobService;
import com.webwork.mood.util.Paging;
import com.webwork.mood.util.StrManager;

@Service
public class JobServiceImpl implements JobService {

	@Autowired
	private JobDao jobDao;
	
	@Override
	public void insert(Job job) {
		jobDao.insert(job);
	}
	
	@Override
	public void update(Job job) {
		jobDao.update(job);
	}
	
	@Override
	public void save(Job job) {
		if (this.get(job.getJobId()) != null) {
			this.update(job);
		} else {
			this.insert(job);
		}
	}
	
	@Override
	public void delete(String jobId) {
		jobDao.delete(jobId);
	}
	
	@Override
	public List<Job> query(Job job) {
		return this.query(job, new Paging(0, 0));
	}
	
	@Override
	public List<Job> query(Job job, Paging page) {
		return jobDao.query(job, page.getCurrPage(), page.getPageSize());
	}
	
	@Override
	public Job get(String jobId) {
		if (StrManager.isEmpty(jobId)) {
			return null;
		}
		Job queryObj = new Job();
		queryObj.setJobId(jobId);
		List<Job> job = this.query(queryObj);
		if (job != null && job.size() > 0) {
			if (job.size() > 1) {
				System.out.println("存在不止一条记录!");
			} else {
				return job.get(0);
			}
		} else {
			System.out.println("找不到该账号!");
		}
		return null;
	}

	@Override
	public int count(Job job) {
		return jobDao.count(job);
	}

}
